package com.situ.yB2C.address.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.situ.yB2C.address.Service.AddressService;
import com.situ.yB2C.address.pojo.Address;
import com.situ.yB2C.area.pojo.Area;
import com.situ.yB2C.area.service.AreaService;
import com.situ.yB2C.util.ContextUtil;

@Controller
@RequestMapping("/address/")
public class AddressController {

	@Autowired
	private AddressService addressService;
	@Autowired
	private AreaService areaService;
	
	@ResponseBody
	@RequestMapping("doadd")
	public int doaddAddr(Address address,HttpSession session ) {
		//得到登录的买家的用户的ID
		Long userId=ContextUtil.getBuyerUserId(session);
		return addressService.doaddAddress(address,userId,session);
	}
	
	@ResponseBody
	@RequestMapping("list")
	public List<Area> findAllAreaList(ModelAndView modelAndView,Integer  parentCode) {
		return addressService.findAreaListByParentCode(parentCode);
	}
	@ResponseBody
	@RequestMapping("addressList")
	public ModelAndView goAddrList(Address address,Area area, ModelAndView modelAndView){
		modelAndView.addObject("addressList", addressService.findAddressList());
		modelAndView.setViewName("shop/address_table_add");
		modelAndView.setViewName("redirect:/shop/address");
		return modelAndView;
	}
	
//	@RequestMapping("addressList")
//	public ModelAndView goAddrList(Address address,Area area, ModelAndView modelAndView){
//		
//		modelAndView.addObject("areaList", areaService.findAreaListByParentCode(null));
//		modelAndView.addObject("addressList", addressService.findAddressList());
//		modelAndView.setViewName("redirect:/shop/address");
//		return modelAndView;
//	}
	
	
	
	
	
	
	
}
